﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using WgFrame.Net;

public class CommonUtil
{
    /// <summary>
    /// 白色
    /// </summary>
    public static readonly Color White = Color.white;
    /// <summary>
    /// 青色
    /// </summary>
    public static readonly Color Cyan = Color.cyan;
    /// <summary>
    /// 绿色
    /// </summary>
    public static readonly Color Green = Color.green;
    /// <summary>
    /// 红色
    /// </summary>
    public static readonly Color Red = Color.red;
    /// <summary>
    /// 紫色
    /// </summary>
    public static readonly Color Magenta = Color.magenta;
    /// <summary>
    /// 橙色
    /// </summary>
    public static readonly Color Orange = new Color(231 / 255f, 101 / 255f, 6 / 255f);
    /// <summary>
    /// 金色
    /// </summary>
    public static readonly Color Golden = new Color(1f, 215 / 255f, 0);


    public static string NumberToString(long number)
    {
        if (number < 10000)
        {
            return number.ToString();
        }
        else if (number < 100000000)
        {
            long n = number / 10000;
            return string.Format("{0}万", n);
        }
        else
        {
            long n = number / 100000000;
            return string.Format("{0}亿", n);
        }
    }

    public static float GetRate(float value)
    {
        return value / 10000 * 100;
    }

    public static int GetDujieValue1(int dujieLevel)
    {
        return (dujieLevel - 1) / 10;
    }

    public static int GetDujieValue2(int dujieLevel)
    {
        return (dujieLevel - 1) % 10 + 1;
    }

    public static string GetJobName(int job)
    {
        string[] jobName = new string[] { "盾", "医", "辅", "战" };
        if (job >= 0 && job < jobName.Length)
        {
            return jobName[job];
        }
        else
        {
            return "";
        }
    }

    public static string GetEquipPosName(int pos)
    {
        string name = "";
        if (pos == 1)
        {
            name = "攻击";
        }
        else if (pos == 2)
        {
            name = "物防";
        }
        else if (pos == 3)
        {
            name = "生命";
        }
        else
        {
            name = "法防";
        }
        return name;
    }

    public static string GetDuJieName(int dujieLevel)
    {
        int d = GetDujieValue1(dujieLevel);
        int g = GetDujieValue2(dujieLevel);
        if (d == 0)
        {
            return string.Format("练气境{0}阶", g);
        }
        else if (d == 1)
        {
            return string.Format("筑基境{0}阶", g);
        }
        else if (d == 2)
        {
            return string.Format("融合境{0}阶", g);
        }
        else if (d == 3)
        {
            return string.Format("金丹境{0}阶", g);
        }
        else if (d == 4)
        {
            return string.Format("元婴境{0}阶", g);
        }
        else if (d == 5)
        {
            return string.Format("出窍境{0}阶", g);
        }
        else if (d == 6)
        {
            return string.Format("分神境{0}阶", g);
        }
        else if (d == 7)
        {
            return string.Format("合体境{0}阶", g);
        }
        else if (d == 8)
        {
            return string.Format("洞虚境{0}阶", g);
        }
        else if (d == 9)
        {
            return string.Format("大乘境{0}阶", g);
        }
        else if (d == 10)
        {
            return string.Format("散仙境{0}阶", g);
        }
        else if (d == 11)
        {
            return string.Format("游仙境{0}阶", g);
        }
        else if (d == 12)
        {
            return string.Format("真仙境{0}阶", g);
        }
        else if (d == 13)
        {
            return string.Format("玄仙境{0}阶", g);
        }
        else if (d == 14)
        {
            return string.Format("天仙境{0}阶", g);
        }
        else if (d == 15)
        {
            return string.Format("太乙玉仙境{0}阶", g);
        }
        else if (d == 16)
        {
            return string.Format("元神玉仙境{0}阶", g);
        }
        else if (d == 17)
        {
            return string.Format("空玄玉仙境{0}阶", g);
        }
        else if (d == 18)
        {
            return string.Format("万劫玉仙境{0}阶", g);
        }
        else
        {
            return string.Format("分神境{0}阶", g);
        }
    }

    /// <summary>
    /// 品质颜色
    /// </summary>
    /// <param name="pinzhi"></param>
    /// <returns></returns>
    public static Color GetHeroPinZhiColor(int pinzhi)
    {
        if (pinzhi == 1)
        {
            return Cyan;
        }
        else if (pinzhi == 2)
        {
            return Magenta;
        }
        else if (pinzhi == 3)
        {
            return Orange;
        }
        else if (pinzhi == 4)
        {
            return Red;
        }
        else if (pinzhi == 5)
        {
            return Golden;
        }
        else
        {
            return Cyan;
        }
    }

    /// <summary>
    /// 渡劫境阶颜色
    /// </summary>
    public static Color GetHeroDuJieColor(int DuJie)
    {
        int d = (DuJie - 1) / 10;
        if (d == 0)
        {
            return White;
        }
        else if (d == 1)
        {
            return Green;
        }
        else if (d == 2)
        {
            return Cyan;
        }
        else if (d == 3)
        {
            return Magenta;
        }
        else if (d == 4)
        {
            return Orange;
        }
        else if (d == 5)
        { 
            return Red;
        }
        else if (d == 6)
        {
            return Golden;
        }
        else if (d == 7)
        {
            return Golden;
        }
        else
        {
            return White;
        }
    }

    /// <summary>
    /// 装备颜色
    /// </summary>
    /// <param name="pinzhi"></param>
    /// <returns></returns>
    public static Color GetEquipColor(int pinzhi)
    {
        if (pinzhi == 1)
        {
            return Cyan;
        }
        else if (pinzhi == 2)
        {
            return Magenta;
        }
        else if (pinzhi == 3)
        {
            return Orange;
        }
        else if (pinzhi == 4)
        {
            return Red;
        }
        else if (pinzhi == 5)
        {
            return Golden;
        }
        else
        {
            return Cyan;
        }
    }

    public static Color GetItemColor(int pinzhi)
    {
        if (pinzhi == 1)
        {
            return Green;
        }
        else if (pinzhi == 2)
        {
            return Cyan;
        }
        else if (pinzhi == 3)
        {
            return Magenta;
        }
        else if (pinzhi == 4)
        {
            return Orange;
        }
        else if (pinzhi == 5)
        {
            return Red;
        }
        else 
        {
            return Green;
        }
    }
    public static void ChangeEquip(byte szPos, int equipType)
    {
        List<Equip> equips = GameNetwork.Player.PackEquipMgr.GetEquipListByType(equipType);
        if (equips.Count == 0)
        {
            FlyTextPanelMgr.Show("没有可用装备");
            return;
        }
        PopupPanelManager.Open<ChangeEquipPanel>(szPos, equips);
    }

    public static bool ChangeHero(byte pos)
    {
        List<Hero> heroes = GameNetwork.Player.PackHeroMgr.GetAll();
        if (heroes.Count == 0)
        {
            FlyTextPanelMgr.Show("没有可用伙伴");
            return false;
        }

        PopupPanelManager.Open<ChangeHeroPanel>(pos, heroes);
        return true;
    }
}
